//
//  NetworkingTools.swift
//  AFNetWorkingTools
//
//  Created by 简康达 on 16/5/13.
//  Copyright © 2016年 JKD. All rights reserved.
//

import UIKit
import AFNetworking
enum MethodType {
    case GET
    case POST
}
class NetworkTools: AFHTTPSessionManager {
    // 将工具类设计成单例对象
    static let shareIntance : NetworkTools = NetworkTools()
}
extension NetworkTools{
    func request(Met :MethodType,URLString:String,parameters:[String:AnyObject],finished:(result:AnyObject?,error:NSError?)->()){
//        定义成功回调
        let successCellBack = { (task:NSURLSessionDataTask,result:AnyObject?)in
            finished(result: result, error: nil)
        }
//        定义失败回调
        let failureCellBack = { (task:NSURLSessionDataTask?,error:NSError)in
            finished(result: nil, error: error)
        }
        
        if Met == .GET{
            GET(URLString, parameters: parameters, success: successCellBack, failure: failureCellBack)}else{
        POST(URLString,parameters : parameters,progress : { (nil) in
            },success : successCellBack,failure : failureCellBack)}
    }
}


